package com.flyan.game.motafx.core.pojo;

import cn.hutool.core.collection.CollUtil;
import lombok.Data;

import java.util.Collections;
import java.util.Set;

/**
 * 生命面板
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/5
 */
@Data
public class LifePanel implements Cloneable {

    /**
     * 生命值
     */
    private int hp;

    /**
     * 攻击力
     */
    private int ack;

    /**
     * 防御力
     */
    private int def;

    /**
     * 金币数量
     */
    private int gold;

    /**
     * 能力/属性
     */
    private Set<String> abilities;

    public LifePanel(int hp, int ack, int def, int gold, Set<String> abilities) {
        this.hp = hp;
        this.ack = ack;
        this.def = def;
        this.gold = gold;
        this.abilities = abilities;
    }

    public LifePanel(int hp, int ack, int def, int gold) {
        this(hp, ack, def, gold, Collections.emptySet());
    }

    public boolean isDead() {
        return hp <= 0;
    }

    public void increaseHp(int hp) {
        this.hp += hp;
    }

    public void increaseAck(int ack) {
        this.ack += ack;
    }

    public void increaseDef(int def) {
        this.def += def;
    }

    public void increaseGold(int gold) {
        this.gold += gold;
    }

    public void addAbility(String  ability) {
        this.abilities.add(ability);
    }

    public void removeAbility(String ability) {
        this.abilities.remove(ability);
    }

    @Override
    public LifePanel clone() {
        try {
            LifePanel clone = (LifePanel) super.clone();
            clone.setAbilities(CollUtil.newHashSet(abilities));
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }

}
